package org.brisling.supply.service;

import java.util.List;

import org.brisling.base.domain.ListDomain;
import org.brisling.base.domain.RetDomain;
import org.brisling.common.ConstSysParam;
import org.brisling.supply.domain.SupplyBaseInfo;
import org.brisling.supply.repository.SupplyBaseinfoRepo;
import org.brisling.sysman.service.base.BaseSysmanTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;


@RestController
@RequestMapping("/supplyBaseinfo")
/**
 * 用戶后台服務service
 * @Author : jackson wang
 * @Date   : 2015年6月8日 下午4:18:01
 * @version: 1.0
 */
public class SupplyBaseinfoService extends BaseSysmanTypeService<SupplyBaseInfo>{
	
	@SuppressWarnings("unused")
	@Autowired
	private SupplyBaseinfoRepo baseRepo;
	
	public SupplyBaseinfoService(){
		this.moduleName = ConstSysParam.MODULE_SUPPLY_BASEINFO;
		
		this.clazz = SupplyBaseInfo.class;
	}
	
	/**
	 * 获取业务主页面 
	 * @return
	 */
	@RequestMapping("/mainPage.action")
	public ModelAndView getMainPage(){
		this.subSystem = "supply";
		return getBizMainPage();
	}
	
	/**
	 * 获取业务编辑页面
	 * @return
	 */
	@RequestMapping("/editPage.action")
	public ModelAndView getEditPage(){
		this.subSystem = "supply";
		return getBizEditPage();
	}
	
	
	/**
	 * 分页查询用户列表页面
	 * @param deptid
	 * @param page
	 * @param rows
	 * @param sort
	 * @return
	 */
	@RequestMapping("/getListDomain.action")
	public ListDomain<SupplyBaseInfo> getListDomain(
			@RequestParam(value="page",required=false) String page,
			@RequestParam(value="rows",required=false) String rows,
			@RequestParam(value="sort",required=false) String sort){
		
		
		return super.getPagedList(page, rows);
			
	}
	
	/**
	 * 分页查询用户列表页面
	 * @param deptid
	 * @param page
	 * @param rows
	 * @param sort
	 * @return
	 */
	@RequestMapping("/getTypeListDomain.action")
	public ListDomain<SupplyBaseInfo> getTypedListDomain(
			@RequestParam(value="page",required=false) Integer page,
			@RequestParam(value="rows",required=false) Integer rows,
			@RequestParam(value="typeid",required=false) Long typeId,			
			@RequestParam(value="sort",required=false) String sort){		
		
		
		return super.getPagedListDomainByTypeId(typeId, page, rows);
			
	}
	
	/**
	 * 分页查询用户列表页面
	 * @param deptid
	 * @param page
	 * @param rows
	 * @param sort
	 * @return
	 */
	@RequestMapping("/getList.action")
	public List<SupplyBaseInfo> getPagedListRows(
			@RequestParam(value="page",required=false) String page,
			@RequestParam(value="rows",required=false) String rows,
			@RequestParam(value="sort",required=false) String sort){
		
		
			return super.getAll(page,rows,getSort(sort));
			
	}
	
	/**
	 * 删除记录,单条或批量删除记录,id不为空，执行单条删除，id为空且ids不为空，执行批量删除
	 * @param id	待删除的单条记录id
	 * @param ids	待删除的多条记录id，以','分隔
	 * @return
	 */
	@RequestMapping("/del.action")
	public RetDomain delRow(@RequestParam(value="id",required=false) Long id,@RequestParam(value="ids",required=false) String ids){
				
		return super.delRows(id, ids);		 
	}
	
	@RequestMapping("/flowDel.action")
	public RetDomain flowDel(@RequestParam(value="id",required=false) Long id,@RequestParam(value="ids",required=false) String ids){
		return this.delRow(id,ids);	
	}
	
	
	/**
	 * 删除组织节点
	 * @param id
	 */
	@RequestMapping("/save.action")
	public SupplyBaseInfo save(@RequestBody String body){
		SupplyBaseInfo obj = bodyToObj(body, SupplyBaseInfo.class);		
		super.save(obj);
		return obj;
	}
	
	/**
	 * 批量审核
	 * @param ids
	 * @param status
	 * @return
	 */
	@RequestMapping("/auditList.action")
	public RetDomain setAuditStatusList(@RequestParam(value="ids",required=false) String ids,@RequestParam(value="status",required=false)String status){
		
		RetDomain domain  = new RetDomain();
		if( (ids!=null) && (status !=null)){
			 int num = super.updateAuditStatusList(ids, status);
			 System.out.println("ids="+ids+" status="+status+" num="+num);
			 domain.setSuccessMsg(num+"");
		}else{
			 domain.setErrorMsg("error");
		}
		
		return domain;
	}
	
	
	
}
